// pages/collection/collection.js
var mockData = require('../../mock/positions.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
	  nextPageUrl: true,
	  pageNum: 1,
	  positions: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  var that = this;
	  this.getMyCollection(this.data.pageNum);
  },
  getMyCollection: function (page) {
	  var that = this;
	  app.apiGet(app.apiList.collectionsList, { page: page }, function (res) {
		  if (res.code == 200) {
			  let newpositions = that.data.positions.concat(res.data.positions);
			  let newpageNum = ++that.data.pageNum;
			  that.setData({
				  positions: newpositions,
				  nextPageUrl: res.data.next_page_url,
				  pageNum: newpageNum
			  })
		  }
	  })
  },

  //share 统一分享
  onShareAppMessage: function (res) {
	  if (res.from === 'button') {
		  // 来自页面内转发按钮
		  console.log(res.target)
	  }
	  return {
		  title: '财咖｜会计招聘找工作',
		  path: '/pages/index/index',
		  imageUrl: '/images/share.jpg',
		  success: function (res) {
			  // 转发成功
		  },
		  fail: function (res) {
			  // 转发失败
		  }
	  }
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
	  if (this.data.nextPageUrl) {
		  this.getMyCollection(this.data.pageNum);
	  }
  },
  //进入详情页面
  positionDetailTap: function (e) {
	  var id = e.currentTarget.dataset.positionId;
	  wx.navigateTo({
		  url: '/pages/detail/detail?id=' + id,
	  })
  }
})